<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-weixinMenu-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">上级菜单：</label>
            <div class="col-sm-8">
                <select class="form-control" id="parentId" name="parentId">
                    <option value="0" th:if="${menuSize} < 3">无 </option>
                    <option th:each="menu:${menuList}" th:value="${menu.id}">
                        [[${menu.name}]]
                    </option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单标题：</label>
            <div class="col-sm-8">
                <input id="name" name="name" class="form-control" type="text">
            </div>
        </div>

        <!--		<div class="form-group">
                    <label class="col-sm-3 control-label">菜单的响应动作类型：</label>
                    <div class="col-sm-8">
                        <input id="menuType" name="menuType" class="form-control" type="text">
                    </div>
                </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单的响应动作类型：</label>
            <div class="col-sm-8">
                <label class="radio-box">
                    <div >
                        <input type="radio" checked="" value="" name="menuType" style="position: absolute; opacity: 0;">
                        <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                    </div>
                    无
                </label>
                <label class="radio-box">
                    <div >
                        <input type="radio" value="view" name="menuType" style="position: absolute; opacity: 0;">
                        <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                    </div>
                    网页类型
                </label>
                <label class="radio-box">
                    <div>
                        <input type="radio"  value="click" name="menuType" style="position: absolute; opacity: 0;">
                        <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                    </div>
                    点击
                </label>
                <label class="radio-box">
                    <div>
                        <input type="radio"  value="miniprogram" name="menuType" style="position: absolute; opacity: 0;">
                        <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                    </div>
                    小程序
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单KEY值：</label>
            <div class="col-sm-8">
                <input id="menuKey" name="menuKey" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">网页 链接：</label>
            <div class="col-sm-8">
                <input id="url" name="url" class="form-control" type="text">
            </div>
        </div>
        <!--<div class="form-group">	-->
        <!--<label class="col-sm-3 control-label">调用新增永久素材接口返回的合法media_id：</label>-->
        <!--<div class="col-sm-8">-->
        <!--<input id="mediaId" name="mediaId" class="form-control" type="text">-->
        <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">小程序的appid：</label>
            <div class="col-sm-8">
                <input id="appid" name="appid" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">小程序的页面路径：</label>
            <div class="col-sm-8">
                <input id="pagepath" name="pagepath" class="form-control" type="text">
            </div>
        </div>
        <!--			<div class="form-group">
                        <label class="col-sm-3 control-label">创建者：</label>
                        <div class="col-sm-8">
                            <input id="createBy" name="createBy" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">创建时间：</label>
                        <div class="col-sm-8">
                            <input id="createTime" name="createTime" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">更新者：</label>
                        <div class="col-sm-8">
                            <input id="updateBy" name="updateBy" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">更新时间：</label>
                        <div class="col-sm-8">
                            <input id="updateTime" name="updateTime" class="form-control" type="text">
                        </div>
                    </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "wx/menu"
    $("#form-menu-add").validate({
        onkeyup: false,
        rules: {
            xxxx: {
                required: true,
            },
        }
    });
    $(function() {
        $("#menuKey").parents(".form-group").hide();
        $("#url").parents(".form-group").hide();
        $("#appid").parents(".form-group").hide();
        $("#pagepath").parents(".form-group").hide();
        $('input').on('ifChecked', function(event){
            var menuType = $(event.target).val();
            // console.log(menuType);
            if (menuType == "view") {
                $("#menuKey").parents(".form-group").hide();
                $("#url").parents(".form-group").show();
                $("#appid").parents(".form-group").hide();
                $("#pagepath").parents(".form-group").hide();
            } else if (menuType == "click") {
                $("#menuKey").parents(".form-group").show();
                $("#url").parents(".form-group").hide();
                $("#appid").parents(".form-group").hide();
                $("#pagepath").parents(".form-group").hide();
            } else if (menuType == "miniprogram") {
                $("#menuKey").parents(".form-group").hide();
                $("#url").parents(".form-group").show();
                $("#appid").parents(".form-group").show();
                $("#pagepath").parents(".form-group").show();
            } else {
                $("#menuKey").parents(".form-group").hide();
                $("#url").parents(".form-group").hide();
                $("#appid").parents(".form-group").hide();
                $("#pagepath").parents(".form-group").hide();
            }
        });
    });
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/addDo", $('#form-menu-add').serialize());
        }
    }
    function selectTree() {
        var id = $("#treeId").val();
        var options = {
            title: '选择上级',
            width: "380",
            url: prefix + "/selectTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        // 不允许最后层级节点选择
        // if ($.tree.notAllowLastLevel(tree)) {
        //     var body = layer.getChildFrame('body', index);
        //     $("#treeId").val(body.find('#treeId').val());
        //     $("#treeName").val(body.find('#treeName').val());
        //     layer.close(index);
        // }
    }
</script>
</body>
</html>
